/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crear;

import apunte.*;
import com.sun.media.ui.ComboBox;
import dataBase.Db;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/**
 *
 * @author martinLequerica
 */
public class aniadirCarrera extends JFrame {
    
    private ComboBox cmbCarrera;
    private LinkedList<Carrera> llc;
    private JButton aceptar,cancelar;
    private Carrera ca;
    
    public aniadirCarrera(final LinkedList llcs,Statement st) throws SQLException{
        super("Agregar Carrera");
        
        setLayout(new GridLayout(2, 5));
        setSize(400, 100);
        setLocation(510, 510);
              
        
        
        //inicializo variables
        cmbCarrera = new ComboBox();
        llc = new LinkedList();
        
        
        
//        Db db = new Db();
//        Statement st = db.getStatement();
        ResultSet eq = st.executeQuery("select * from carrera");
        
        
        while (eq.next()){
            
            llc.add(new Carrera(eq.getInt("idcarrera"), eq.getString("nombreCarrera"), eq.getString("jefeDeDepartamento")));
            
        }
        
        for (int i = 0; i<llc.size();i++){
            
            cmbCarrera.add(llc.get(i).getNombreCarrera());
            
            
        }
        cmbCarrera.setSize(50, 100);
        add(new JLabel("Seleccione Carrera"));
        add(cmbCarrera);
        
        //botones
        
        aceptar = new JButton("Aceptar");
        cancelar = new JButton("Cancelar");
        
        add(aceptar);
        add(cancelar);
        
        
        aceptar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
           
                ca = new Carrera(llc.get(cmbCarrera.getSelectedIndex()).getIdcarrera(),llc.get(cmbCarrera.getSelectedIndex()).getNombreCarrera(),llc.get(cmbCarrera.getSelectedIndex()).getJefeDeDepartamento());
                llcs.add(ca);
                setVisible(false);
            }
        });
        
        
        setVisible(true);
        
        
    }
    
    
    
    
    

    
    
    
}
